<template>
	<view class="pagebody">
		<view class="p10">
			<view :class="isHistory==0?'span-view done-tab done-tab-active':'span-view done-tab'" style="width: 50%;" @click="historyChange(0)" >
				未完结
			</view>
			<view :class="isHistory==1?'span-view done-tab done-tab-active':'span-view done-tab'" style="width: 50%;"  @click="historyChange(1)">
				已完结
			</view>
		</view>
		<view>
			<uni-search-bar placeholder="请输入标题关键字"   @input="search"></uni-search-bar>
		</view>
		
		<view class="task-carlist">
			<uni-card   class="task-card" @click="openWorkflowfromView(r)"  :key="index" v-for="(r,index) in rows"   
			   
			 note="true">
			 <view class="car-header-box">
			 	<view v-html="r.workflowTitle" class="fl font16"> </view>
			 	<view v-html="r.workflowInstanceState" class="fr"></view>
			 </view>
				<view class="item-text">当前节点：<text class="task_activity_name" >{{r.currentActivityName}}</text> </view>
				<view class="item-text">发  起 人：{{r.creatorRealName}}</view>
				<view class="item-text">发起时间：{{r.startedTime}}</view>
				<template v-slot:footer>
					<view class="car-footer-box">
						<view class="span-view fl">{{r.sheetId}}</view>
						<view class="span-view fr" v-html="r.appName"> </view>
					</view>
				</template>
			</uni-card>
		</view>
		<view class="pagebar">
			<view class="span-view page-btn" v-if="page.pageIndex!=1" @click="firstPage">
				首 页
			</view>
			<view class="span-view page-btn" @click="prePage" v-if="page.pageIndex!=1">
				上一页
			</view>
			<view class="span-view page-btn" @click="nextPage" v-if="page.pageIndex!=page.pageCount">
				下一页
			</view>
			<view class="span-view page-btn" @click="lastPage" v-if="page.pageIndex!=page.pageCount">
				尾 页
			</view>
			<view class="span-view"> 共{{page.total}}条,每页{{page.pageSize}}条,当前第{{page.pageIndex}}页/共{{page.pageCount}}页</view>
		</view>
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
	export default {
		components: {uniSearchBar},
		onLoad: function(option) {
			var that = this;
			var success = that.$store.getters.validateLogin;
			if (!success) {
				FUI.Window.showMsg("您未登录")
				return false;
			}
		},
		onPullDownRefresh: function() {
			//下拉刷新
			var that = this;
			this.loadList(1);
			uni.stopPullDownRefresh();
		},
		
		data() {
			return {
				searchParams:{
					workflowTitle:''
				}
				,isHistory:0,
				page: {
					sortName: "createdTime",
					order: "desc",
					pageSize: 10,
					pageIndex: 1,
					pageCount: 0,
					total: 0
				},
				rows: []
			}
		},
		computed: {
			...mapState(['author'])
		},
		created() {
			var that = this;
			this.loadList(1);
		},
		methods: {
			openWorkflowfromView:function(row) {
				var appId = row.appId;
				var formAction = 3;
				var wiid = row.workflowInstanceId;
				var taskId = row.taskId;
				var title = row.workflowTitle;
				var url = __webpath + "/workflow/businessMP/workflowform?formAction="+formAction+"&wiid=" + wiid ;
				FUI.Window.ngto(url);
				
			},
			historyChange(isHistory){
				var that=this;
				that.isHistory=isHistory;
				that.loadList(1);
			}
			,search(v){
				var that=this;
				that.searchParams.workflowTitle=v.value;
				console.info(v);
				that.loadList(1);
			}
			,loadList(pageIndex) {
				var that = this;
				var pageSize = that.page.pageSize;
				that.page.pageIndex = pageIndex;
				var parms={
					pageIndex: pageIndex,
					pageSize: pageSize,
					sort: that.page.sortName,
					order: that.page.order,
					isHistory:that.isHistory
				};
				parms.workflowTitle=that.searchParams.workflowTitle;
				
				that.$myObject.toAjaxJson("/rest/api/processEnactmentApi/", "getMyWorkItemList", parms, function(data) {
					that.page.total = data.total;
					that.page.pageCount = data.pageCount;
					that.rows = data.rows;
					that.rows.forEach(function(row) {
						row.workflowInstanceState =  getWorkflowStatus( row.workflowInstanceState);
					});

				});
			},
			firstPage() {
				var that = this;
				that.loadList(1)
			},
			nextPage() {
				var that = this;
				that.loadList(that.page.pageIndex + 1)
			},
			prePage() {
				var that = this;
				that.loadList(that.page.pageIndex - 1)
			},
			lastPage() {
				var that = this;
				that.loadList(that.page.pageCount)
			}
		}
	}
</script>

<style>

</style>
